package order.orders;

import order.creator.MakeChocolateCake;
import order.creator.MakeFruityCake;
import order.creator.MakeMilkCake;
import order.jdbc.JDBCFacade;
import order.product.ChocolateFactory;
import order.product.FruitFactory;
import order.product.MilkFactory;

/**
 * 具体观察者一  EastVilla
 */
public class EastVilla implements Customer{
    Shop shop;
    private String cakeType;

    public EastVilla(Shop shop,String cakeType){
        this.shop = shop;
        this.cakeType = cakeType;
        shop.addCustomer(this);
    }

    public void orderCake(String name){
        System.out.println(name+"订了一个"+cakeType+"蛋糕");
        JDBCFacade dbFacade=new JDBCFacade();
        String sqlStr = "select * from ordercake";
        String sqlStr1 = "insert into ordercake(cakeType, name, quantity)"+ " VALUES ('"+cakeType+"','"+name+"','1')";
        System.out.println(cakeType);
        System.out.println(name);
        dbFacade.jdbcInsert(sqlStr1);
        System.out.println("查询插入之后新的数据库");
        dbFacade.jdbcSelect(sqlStr);
        if(cakeType.equals("草莓水果") || cakeType.equals("葡萄水果")){
            MakeFruityCake eastVilla = new MakeFruityCake(cakeType);
            FruitFactory fruitCake = eastVilla.makeFruityCake();
            fruitCake.createCake();
        }
        else if(cakeType.equals("牛奶巧克力") || cakeType.equals("黑巧克力")){
            MakeChocolateCake eastVilla1 = new MakeChocolateCake(cakeType);
            ChocolateFactory chocolateCake = eastVilla1.makeChocolateCake();
            chocolateCake.createCake();
        }
        else if(cakeType.equals("双层鲜奶") || cakeType.equals("甜奶")){
            MakeMilkCake eastVilla1 = new MakeMilkCake(cakeType);
            MilkFactory milkCake =eastVilla1.makeMilkCake();
            milkCake.createCake();
        }
    }
}
